package com.stx.stcp.controller;

import com.github.pagehelper.PageInfo;
import com.stx.stcp.bean.MenuBean;
import com.stx.stcp.service.MenuService;
import com.stx.stcp.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class IndexController {
    @Autowired
    TypeService typeService;
    @Autowired
    MenuService menuService;
    @RequestMapping("/")
    public String index(){
        return "redirect:/main";
    }
    @RequestMapping("main")
    public String main(Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
        List list=typeService.allTypes();
        model.addAttribute("types",list);
        List mlist = menuService.menuList(pageNum);
        PageInfo<MenuBean> pageInfo = new PageInfo<MenuBean>(mlist);
        model.addAttribute("pageInfo",pageInfo);
        return "front/index";
    }
}
